package com.xiaoma.pattern.proxy.jdk.strategy.impl;

import com.xiaoma.pattern.proxy.jdk.strategy.Strategy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class BuyInsuranceStrategy implements Strategy {


  @Override
  public Object invoke(Object proxy, Method method, Object[] args, Object target) {
    if (method.getName().equals("buyInsure")) {
      System.out.println("策略buyInsure执行：");
    } else {
      System.out.println("执行原方法");
    }

    Object result = null;
    try {
      result = method.invoke(target, args);
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
    return result;
  }
}
